package com.hbzhit.modules.nm.controller;

import com.hbzhit.common.extension.BaseController;
import com.hbzhit.common.utils.PageUtils;
import com.hbzhit.common.utils.R;
import com.hbzhit.common.utils.ShiroUtils;
import com.hbzhit.modules.nm.entity.NoticeEntity;
import com.hbzhit.modules.nm.form.NoticeQueryForm;
import com.hbzhit.modules.nm.service.NoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;

/**
 * 系统消息通知
 *
 * @author Tiger.Zhang
 * 2020-01-09 11:11
 */
@Api(tags = {"消息通知 "})
@AllArgsConstructor
@RestController
@RequestMapping("/nm/notice")
public class NoticeController extends BaseController<NoticeService, NoticeEntity> {

    /**
     * 查询个人消息通知
     */
    @ApiOperation(value = "个人消息通知列表", notes = "默认查询当前用户消息")
    @GetMapping("/myPage")
    public R<PageUtils<NoticeEntity>> myPage(NoticeQueryForm params) {
        if (params.getUserId() == null) {
            params.setUserId(ShiroUtils.getUserId());
        }
        PageUtils<NoticeEntity> page = baseService.queryPage(params);
        return R.ok(page);
    }
    
    @ApiOperation(value = "设置消息已读")
    @PostMapping("/read")
    public R<Object> read(@RequestBody Collection<Long> idList) {
        baseService.readNotice(idList);
        return R.ok();
    }

    @ApiOperation(value = "设置当前用户消息已删除")
    @PostMapping("/delNotice")
    public R<Object> delete(@RequestBody Collection<Long> idList) {
        baseService.delNotice(idList);
        return R.ok();
    }

}
